import torchvision

trans_compose = torchvision.transforms.Compose([
    torchvision.transforms.ToTensor(),
])

# 将数据集转为Tensor类型
train_set = torchvision.datasets.CIFAR10(root="./dataset", transform=trans_compose, train=True, download=True)
test_set = torchvision.datasets.CIFAR10(root="./dataset", transform=trans_compose, train=False, download=True)

# print(train_set[0])
# img, target = train_set[0]
# print(train_set.classes)
# print("target=%s, classes=%s" % (target, train_set.classes[target]))
# img.show()


import torch.utils.tensorboard as tensorboard
writer = tensorboard.SummaryWriter(log_dir='./logs')

for i in range(100):
    img, target = train_set[i]
    writer.add_image('test torchvision.dataset', img, i)

writer.close()